<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="/css/elementui/index.css">
<link rel="stylesheet" href="/css/exam/css/style.css">
<link rel="stylesheet" href="/iconfont/iconfont.css">
</head>
<body>
<div id="app">
  <div  class="p-30">
      <el-row>
       <el-row style="font-size:14px">
            <span class="icon iconfont icon-arrow_back"></span>  <a href="{{route('admin.examview.papercidlist')}}">返  回</a> | 添加试卷分类
        </el-row><br>
      </el-row><br>
      <el-form :model="addCidForm" :rules="rules" ref="addCidForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="分类名" prop="p_name">
                <el-input v-model="addCidForm.p_name"></el-input>
            </el-form-item>
            <el-form-item label="排&ensp;&ensp;序" prop="p_sort">
                <el-input v-model="addCidForm.p_sort"></el-input>
            </el-form-item>
			 

            <el-row>
                <el-button @click="saveCid('addCidForm')" type="primary" v-debounce>保&ensp;&ensp;存</el-button>
                <el-button @click="cancelCid('addCidForm')">取&ensp;&ensp;消</el-button>
            </el-row>         
        </el-form>

  </div>

</div>
</body>
<script src="/css/exam/js/vue.js"></script>
<script src="/css/elementui/index.js"></script>
<script src="/css/exam/js/axios.min.js"></script>
<script src="/css/exam/js/common.js"></script>
<script>

const app = new Vue({
  el: '#app',
  data() {
    return { 
        addCidForm: {
        p_name: '',
        p_sort: '',
        },

        cidData: [], //分类数据

        rules: {
            p_name: [
             { required: true, message: '请输入分类标题', trigger: 'blur' },
             { min: 2, max: 60, message: '长度在 2 到 60 个字符', trigger: 'blur' }
            ],
            p_sort: [
             { required: true, message: '请输入整数', trigger: 'blur' },
             { pattern: /^[0-9]*$/, message: '请输入整数', trigger: 'blur' }
            ]
        },
    }
    
  },
  created() {

  },
  methods: {
        // 编辑、增加页面保存方法
        saveCid(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {

                let p_name = this.addCidForm.p_name;
                let p_sort = this.addCidForm.p_sort;
                axios.post('/admin/paper/category_edit',{p_name:p_name,p_sort:p_sort})
                .then(res => {
                if (res.data.code == 0) {  
                    
                    this.$message({
                    type: 'success',
                    message: '保存成功！'
                    });
                    this.$refs[formName].resetFields();
                } else if(res.data.code == 408){
					this.$message({
						type: 'info',
						message: '该名称已存在，请重新录入！'
					})
				} else{
					this.$message({
						type: 'info',
						message: '网络原因，请稍后再试'
					})
				}
                })
          } else {
            return false;
          }
        });
      },
 
        cancelCid(formName) {
            this.$refs[formName].resetFields();
        },
        },


      
})

</script>
<style>
  a{color:#409EFF;text-decoration: none;}
</style>
</html>

